package cn.tedu.ivoswork.user.controller;

import cn.tedu.ivoswork.base.response.JsonResult;
import cn.tedu.ivoswork.user.pojo.dto.UserLoginParam;
import cn.tedu.ivoswork.user.pojo.dto.UserQuery;
import cn.tedu.ivoswork.user.pojo.dto.UserSaveParam;
import cn.tedu.ivoswork.user.pojo.vo.UserVO;
import cn.tedu.ivoswork.user.service.impl.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/user")
public class UserController {

    @Autowired
    UserService userService;

    @PostMapping("login")
    public JsonResult login(UserLoginParam userLoginParam){
        log.debug("用户登录，参数：{}",userLoginParam);
        UserVO userVO = userService.login(userLoginParam);
        return JsonResult.ok(userVO);
    }
    @GetMapping("select")
    public JsonResult select(UserQuery userQuery){
        log.debug("用户查询，参数：{}",userQuery);
        List<UserVO> list = userService.select(userQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    public JsonResult save(UserSaveParam userSaveParam){
        log.debug("保存用户，参数：{}",userSaveParam);
        userService.save(userSaveParam);
        return JsonResult.ok();
    }
    @PostMapping("update/status")
    public JsonResult changeStatus(Long id,String status){
        log.debug("修改状态，参数：{},{}",id,status);
        userService.changeStatus(id,status);
        return JsonResult.ok();
    }
    @PostMapping("update/password")
    public JsonResult resetPassword(Long id){
        log.debug("密码重置，参数：{}",id);
        userService.resetPassword(id);
        return JsonResult.ok();
    }
    @PostMapping("delete")
    public JsonResult update(Long id){
        log.debug("删除用户，参数：{}",id);
        userService.delete(id);
        return JsonResult.ok();
    }

}
